#pragma once


#include <vector>
#include "object/Object.hpp"
#include "trace/HitResult.hpp"


class Scene
{
public:
    Scene() {}

    void addObject(std::unique_ptr<Object>&& pObject)
    {
        if (pObject != nullptr)
            _objects.push_back(std::move(pObject));
    }

    void clear()
    {
        _objects.clear();
    }

    std::unique_ptr<HitResult> hitTest(const Ray& ray) const
    {
        std::unique_ptr<HitResult> pHitResult = nullptr;
        for (const auto& pObject : _objects)
        {
            std::unique_ptr<HitResult> pTempHitResult = pObject->hitTest(ray);
            if (pTempHitResult != nullptr)
            {
                if (pHitResult == nullptr || pTempHitResult->rayParameter() < pHitResult->rayParameter())
                    pHitResult = std::move(pTempHitResult);
            }
        }
        return pHitResult;
    }

private:
    std::vector<std::unique_ptr<Object>> _objects;      // objects in the scene
};